C51 COMPILER V9.60.0.0   MAIN                                                              10/12/2022 17:14:18 PAGE 1   


C51 COMPILER V9.60.0.0, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN .\Release\main.obj
COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE main.c OPTIMIZE(0,SPEED) REGFILE(.\Release\Sample_DrvI2C_Slave.ORC) BROW
                    -SE INCDIR(..\..\..\..\C51SIS\C51;..\..\..\Include\Driver) DEBUG OBJECTEXTEND TABS(2) OBJECT(.\Release\main.obj)

line level    source

   1          /**************************************************************************//**
   2           * @file           main.c
   3           * @version        V1.0
   4           * $Revision:      1 $
   5           * $Date:          2017/01/04 $
   6           * @brief          Main function
   7           * @Author         Jeffrey Kang
   8           * @ContactInfo    chkang@esmt.com.tw
   9           *
  10           * @note
  11           *
  12           * Copyright (C) 1998 Elite Semiconductor Memory Technology Corp.
  13           * All rights reserved.
  14           *
  15           ******************************************************************************/
  16          
  17          
  18          #include <REG52.h>
  19          #include "system_FE81001.h"
  20          
  21           unsigned char xdata rx_buf[3]={0};
  22           
  23          void I2C_Slave_Config();
  24          
  25          /**
  26           * @brief       delay function
  27           *
  28           * @param       None
  29           *
  30           * @return      None
  31           *
  32           * @details     1. 
  33           */
  34          void delay (void)
  35          {
  36   1        unsigned int i;
  37   1        
  38   1        for( i = 0 ; i < 200 ; i++ ){}
  39   1      }
  40          
  41          
  42          /**
  43           * @brief       I2CSISR function
  44           *
  45           * @param       None
  46           *
  47           * @return      None
  48           *
  49           * @details     1. 
  50           */
  51          const void I2CISR (void) interrupt ISR_I2C
  52          {
  53   1        unsigned char  dir;
  54   1      
C51 COMPILER V9.60.0.0   MAIN                                                              10/12/2022 17:14:18 PAGE 2   

  55   1        /* addr hit : check direction */
  56   1      if ((I2C->int_st[0] & 0x08) == 0x08)
  57   1      {
  58   2          I2C->int_st[0] = 0x08;
  59   2          
  60   2          dir = I2C->i2c_ctrl & 0x01;
  61   2          
  62   2          if (dir == 0) // Slave Read  **** (dir == 0)  When master write  will run this section  ****
  63   2            {   
  64   3                  while((I2C->int_st[1] & 0x01) != 0x01){} 
  65   3                  I2C->int_st[1] |= 0x01; 
  66   3                  rx_buf[0] = I2C->i2c_dat; //  Receive 1st data
  67   3                  
  68   3                  while((I2C->int_st[1] & 0x01) != 0x01){} 
  69   3                  I2C->int_st[1] |= 0x01; 
  70   3                  rx_buf[1] = I2C->i2c_dat; //  Receive 2st data
  71   3                      
  72   3                  while((I2C->int_st[1] & 0x01) != 0x01){} 
  73   3                  I2C->int_st[1] |= 0x01;
  74   3                  rx_buf[2] = I2C->i2c_dat; //  Receive 3st data    
  75   3                    
  76   3                  I2C->i2c_cmd = 0x05;
  77   3                  I2C_Slave_Config();       
  78   3              }
  79   2              
  80   2          else  // Slave Write   ****  (dir == 1)  When master read will run this section ,  slave will transfer da
             -ta that master write **** 
  81   2            {
  82   3                   I2C->i2c_dat = rx_buf[0]; //  Transfer 1st data
  83   3                   while((I2C->int_st[0] & 0x80) != 0x80){} 
  84   3                   I2C->int_st[0] |= 0x80;  
  85   3                  I2C->int_st[1] = 0x02;
  86   3                  I2C->i2c_dat = rx_buf[1]; //  Transfer 2st data
  87   3                     
  88   3                  while((I2C->int_st[0] & 0x80) != 0x80){} 
  89   3                   I2C->int_st[0] |= 0x80;
  90   3                  I2C->int_st[1] = 0x02;
  91   3                  I2C->i2c_dat = rx_buf[2]; // Transfer 3st data
  92   3                    
  93   3                  while((I2C->int_st[0] & 0x80) != 0x80){} 
  94   3                  I2C->int_st[0] |= 0x80;
  95   3                  I2C->int_st[1] = 0x02;
  96   3               
  97   3                  I2C->i2c_cmd = 0x05;
  98   3                  I2C_Slave_Config();
  99   3           }
 100   2          
 101   2        }
 102   1        
 103   1        /* byte transmit */
 104   1        if ((I2C->int_st[0] & 0x80) == 0x80){
 105   2          I2C->int_st[0] = 0x80;
 106   2          I2C->int_st[1] = 0x02;
 107   2        }
 108   1        
 109   1        /* Cmpl */
 110   1        if ((I2C->int_st[1] & 0x02) == 0x02){
 111   2          I2C->int_st[1] = 0x02;
 112   2          I2C->int_st[0] = 0x80;
 113   2        }
 114   1        
 115   1        /* enable global interrupt */
C51 COMPILER V9.60.0.0   MAIN                                                              10/12/2022 17:14:18 PAGE 3   

 116   1        INTC->int_gmask = 0x01;
 117   1      }
 118          
 119          
 120          
 121          /**
 122           * @brief       IOConfig function
 123           *
 124           * @param       None
 125           *
 126           * @return      None
 127           *
 128           * @details     1. 
 129           */
 130          void IOConfig()
 131          {
 132   1        /* enable PA.4, PA.5 open drain */
 133   1        PORT_SetPAOpenDrain(BIT4 | BIT5);
 134   1        
 135   1        /* enable PA.4(SCL), PA.5(SDA) function */
 136   1        Set_PA4_SDA();
 137   1        Set_PA5_SCL();  
 138   1        
 139   1      }
 140          
 141          
 142          /**
 143           * @brief       CLKConfig function
 144           *
 145           * @param       None
 146           *
 147           * @return      None
 148           *
 149           * @details     1. 
 150           */
 151          void CLKConfig()
 152          {
 153   1        /* enable GPIO clock */
 154   1        PORT_PAPBPCPD_Clock_Enable();
 155   1        
 156   1        /* enable I2C clock */
 157   1        En_I2C_clk();
 158   1        
 159   1      }
 160          
 161          void I2C_Slave_Config()
 162          {
 163   1        
 164   1          /* set slave address */
 165   1        I2C->slv_adr[0] = 0x48;
 166   1        I2C->slv_adr[1] = 0x00;
 167   1        
 168   1          /* i2c setup */
 169   1        I2C->i2c_setup[0] = 0x01;         // Master = 0, Addressing = 0, IICEN = 1
 170   1        
 171   1        /* timing setup for I2C 400KHz of PCLK 8MHz */
 172   1        I2C_speed_400k_8M();
 173   1        
 174   1        /* interrupt enable */
 175   1        I2C->int_en[0] = 0x88;            // ByteTrans = 1, Start = 0, Stop = 0, ArbLose = 0, AddrHit = 1, FIFOHa
             -lf = 0, FIFOFull = 0, FIFOEmpty = 0
 176   1        I2C->int_en[1] = 0x10;            // Cmpl = 0, ByteRecv = 1
C51 COMPILER V9.60.0.0   MAIN                                                              10/12/2022 17:14:18 PAGE 4   

 177   1        
 178   1      }
 179          
 180          
 181          /**
 182           * @brief       main function
 183           *
 184           * @param       None
 185           *
 186           * @return      None
 187           *
 188           * @details     1. 
 189           */
 190          int main (void)
 191          { 
 192   1        CLKConfig();
 193   1        IOConfig();
 194   1        I2C_Slave_Config();
 195   1        
 196   1        /* enable global interrupt */
 197   1        INTC->int_gmask = 0x01;
 198   1        
 199   1        delay();
 200   1        
 201   1        while(1);
 202   1      }
 203          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    630    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =      3    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      3    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
